package com.limbo.showapp.base;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.support.annotation.Nullable;

/**
 * Created by wangqi on 2018/9/12.
 */

public abstract class BaseService<V extends IBaseView, P extends BasePresenter> extends Service {
    @Nullable
    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }

    protected P mPresenter;

    //抽象方法 获取Presenter对象
    protected abstract P getPresenter();

    @Override
    public void onCreate() {
        super.onCreate();

        //初始化Presenter
        mPresenter = getPresenter();
        if (mPresenter != null)
            mPresenter.attachView((V) this);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        if (mPresenter != null)
            mPresenter.detachView();
    }
}
